package com.danco.training.zaneuskaya.view;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class IOUtil {

	public static final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat(
			"yyyy-MM-dd");

	public static String read() {

		BufferedReader bufferRead = new BufferedReader(new InputStreamReader(
				System.in));

		try {
			return bufferRead.readLine().toString();
		} catch (IOException e) {
			e.getMessage();
			return read();
		}

	}

	public static double readDouble() {
		double number = Double.parseDouble(read());
		return number;

	}

	public static int readInt() {

		try {
			return Integer.parseInt(read());
		} catch (NumberFormatException e) {

			e.getMessage();
			return readInt();
		}

	}

	public static void write(Object... args) {
		StringBuffer str = new StringBuffer();
		for (int i = 0; i < args.length; i++) {
			str.append(args[i]);
		}
		System.out.println(str);

	}

	public static Date readDate() {
		Date date = null;
		try {

			return DATE_FORMAT.parse(read());
		} catch (ParseException e) {
			e.getMessage();
			return date;
		}

	}

}
